#include "Scene.h"
#include "PapaBallSceneManager.h"
//#include "rapidxml.hpp"
#include "DotSceneLoader.h"
#include <math.h>

class MainScene:public Scene
{
public:
	MainScene(SceneEvnArgs evn):Scene(evn){}
	virtual void Initialization() 
	{
		Scene::Initialization();
		//MenuManager::getSingleton().ActiveWindow("unnamed.layout");
	}

	virtual void createScene( void ) 
	{
		SelectedNumber = 0;
		ListType = 0;
		GameNumber = 0;
		VolumeValue = 3;

		//Runscript("MainFrame.lua");
		CEGUI::SchemeManager::getSingleton().create("MySkin.scheme");
		CEGUI::System::getSingleton().setDefaultMouseCursor("MySkinImages", "MouseArrow");
		CEGUI::FontManager::getSingleton().create("Batang-large.font");
		fontBig = &CEGUI::FontManager::getSingleton().get("Batang-large");
		CEGUI::FontManager::getSingleton().create("Batang-small.font");
		fontSmall =  &CEGUI::FontManager::getSingleton().get("Batang-small");
		CEGUI::System::getSingleton().setDefaultFont("Batang-small");
		MenuManager::getSingleton().ActiveWindow("mainFrame.layout");

		mWmg = CEGUI::WindowManager::getSingletonPtr();
		
		/**
			Main
		*/
		MainList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Main");
		
		CEGUI::ItemEntry * MainListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Top");
		MainList->addItem(MainListTop);

		Game=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Game");
		CEGUI::Window* GameText=(CEGUI::Window*)mWmg->getWindow("GameText");
		Game->addChildWindow(GameText);
		MainList->addItem(Game);

		Setting=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Setting");
		CEGUI::Window* SettingText=(CEGUI::Window*)mWmg->getWindow("SettingText");
		Setting->addChildWindow(SettingText);
		MainList->addItem(Setting);

		Achievement=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Achievement");
		CEGUI::Window* AchievementText=(CEGUI::Window*)mWmg->getWindow("AchievementText");
		Achievement->addChildWindow(AchievementText);
		MainList->addItem(Achievement);

		Exit=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Exit");
		CEGUI::Window* ExitText=(CEGUI::Window*)mWmg->getWindow("ExitText");
		Exit->addChildWindow(ExitText);
		MainList->addItem(Exit);

		CEGUI::ItemEntry * MainListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Bottom");
		MainList->addItem(MainListBottom);

		MainList->getVertScrollbar()->setScrollPosition(30);
		Game->getChild("GameText")->setFont(fontBig);
		Game->getChild("GameText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
		Game->select();
		Setting->setHeight(CEGUI::UDim(0,30));
		Achievement->setHeight(CEGUI::UDim(0,30));
		Exit->setHeight(CEGUI::UDim(0,30));
		/**
			GameList
		*/
		GameList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/GameModes");
		//GameList->setVisible(false);

		CEGUI::ItemEntry * GameListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","GameTop");
		GameList->addItem(GameListTop);

		Mode1=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Mode1");
		Mode1->addChildWindow((CEGUI::Window*)mWmg->getWindow("Mode1Text"));
		GameList->addItem(Mode1);

		Mode2=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Mode2");
		Mode2->addChildWindow((CEGUI::Window*)mWmg->getWindow("Mode2Text"));
		GameList->addItem(Mode2);

		CEGUI::ItemEntry * GameListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","GameBottom");
		GameList->addItem(GameListBottom);

		GameList->getVertScrollbar()->setScrollPosition(30);
		Mode1->getChild("Mode1Text")->setFont(fontBig);
		Mode1->getChild("Mode1Text")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
		Mode2->getChild("Mode2Text")->setFont(fontSmall);
		Mode2->getChild("Mode2Text")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
		Mode2->setHeight(CEGUI::UDim(0,30));
		Mode1->select();
		/**
			SettingList
		*/
		SettingList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Setting");
		//SettingList->setVisible(false);

		CEGUI::ItemEntry * SettingListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","SettingTop");
		SettingList->addItem(SettingListTop);

		Volume=(CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","Volume");
		CEGUI::Window* VolumeText=(CEGUI::Window*)mWmg->getWindow("VolumeText");
		Volume->addChildWindow(VolumeText);
		SettingList->addItem(Volume);

		CEGUI::ItemEntry * SettingListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","SettingBottom");
		SettingList->addItem(SettingListBottom);

		SettingList->getVertScrollbar()->setScrollPosition(30);
		Volume->getChild("VolumeText")->setFont(fontBig);
		Volume->getChild("VolumeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
		Volume->select();
		
		/**
			VolumeList
		*/
		VolumeList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Volume");

		CEGUI::ItemEntry * VolumeListTop = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","VolumeTop");
		CEGUI::ItemEntry * VolumeListBottom = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","VolumeBottom");
		
		zero = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","zero");
		zero->addChildWindow((CEGUI::Window*)mWmg->getWindow("zeroText"));
		one = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","one");
		one->addChildWindow((CEGUI::Window*)mWmg->getWindow("oneText"));
		two = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","two");
		two->addChildWindow((CEGUI::Window*)mWmg->getWindow("twoText"));
		three = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","three");
		three->addChildWindow((CEGUI::Window*)mWmg->getWindow("threeText"));
		four = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","four");
		four->addChildWindow((CEGUI::Window*)mWmg->getWindow("fourText"));
		five = (CEGUI::ItemEntry*)mWmg->createWindow("MySkin/ListboxItem","five");
		five->addChildWindow((CEGUI::Window*)mWmg->getWindow("fiveText"));


		VolumeList->addItem(VolumeListTop);
		VolumeList->addItem(zero);
		VolumeList->addItem(one);
		VolumeList->addItem(two);
		VolumeList->addItem(three);
		VolumeList->addItem(four);
		VolumeList->addItem(five);
		VolumeList->addItem(VolumeListBottom);

		//VolumeList->setVisible(false);

		zero->setHeight(CEGUI::UDim(0,30));
		one->setHeight(CEGUI::UDim(0,30));
		two->setHeight(CEGUI::UDim(0,30));
		three->setHeight(CEGUI::UDim(0,30));
		four->setHeight(CEGUI::UDim(0,30));
		five->setHeight(CEGUI::UDim(0,30));

		switch(VolumeValue)
		{
		case 0:
			VolumeList->getVertScrollbar()->setScrollPosition(30);
			zero->getChild("zeroText")->setFont(fontBig);
			zero->getChild("zeroText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setHeight(CEGUI::UDim(0,60));
			zero->select();
			break;
		case 1:
			VolumeList->getVertScrollbar()->setScrollPosition(90);
			one->getChild("oneText")->setFont(fontBig);
			one->getChild("oneText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setHeight(CEGUI::UDim(0,60));
			one->select();
			break;
		case 2:
			VolumeList->getVertScrollbar()->setScrollPosition(150);
			two->getChild("twoText")->setFont(fontBig);
			two->getChild("twoText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setHeight(CEGUI::UDim(0,60));
			two->select();
			break;
		case 3:
			VolumeList->getVertScrollbar()->setScrollPosition(210);
			three->getChild("threeText")->setFont(fontBig);
			three->getChild("threeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
			three->setHeight(CEGUI::UDim(0,60));
			three->select();
			break;
		case 4:
			VolumeList->getVertScrollbar()->setScrollPosition(270);
			four->getChild("fourText")->setFont(fontBig);
			four->getChild("fourText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
			three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,270)));
			four->setHeight(CEGUI::UDim(0,60));
			four->select();
			break;
		case 5:
			VolumeList->getVertScrollbar()->setScrollPosition(330);
			five->getChild("fiveText")->setFont(fontBig);
			five->getChild("fiveText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
			one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
			two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
			three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,270)));
			four->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,330)));
			five->setHeight(CEGUI::UDim(0,60));
			five->select();
			break;
		}


		/**
			Achievement
		*/
		AchievementList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Achievement");
		//AchievementList->setVisible(false);

		/**
			Exit
		*/
		ExitList = (CEGUI::ItemListbox*)mWmg->getWindow("Root/Window/Exit");
		//ExitList->setVisible(false);

		CEGUI::PushButton *Up = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Up");
		CEGUI::PushButton *Down = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Down");
		CEGUI::PushButton *Left = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Left");
		CEGUI::PushButton *Right = (CEGUI::PushButton *)mWmg->getWindow("Root/Window/Right");

		Up->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&MainScene::onUpClick,this));
		Down->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&MainScene::onDownClick,this));
		Left->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&MainScene::onLeftClick,this));
		Right->subscribeEvent(CEGUI::PushButton::EventMouseClick,CEGUI::Event::Subscriber(&MainScene::onRightClick,this));
		

		mAmg = CEGUI::AnimationManager::getSingletonPtr();
		mAmg->loadAnimationsFromXML("myAnimations.xml");

		ChangeSelection1 = mAmg->getAnimation("ChangeSelection1");
		ChangeSelectionIns1 = mAmg->instantiateAnimation(ChangeSelection1);

		ChangeSelection2 = mAmg->getAnimation("ChangeSelection2");
		ChangeSelectionIns2 = mAmg->instantiateAnimation(ChangeSelection2);

		ChangeSelectionTop = mAmg->getAnimation("ChangeSelectionTop");
		ChangeSelectionInsTop = mAmg->instantiateAnimation(ChangeSelectionTop);

		ChangeSelectionBottom = mAmg->getAnimation("ChangeSelectionBottom");
		ChangeSelectionInsBottom = mAmg->instantiateAnimation(ChangeSelectionBottom);

		ShowWindow = mAmg->getAnimation("ShowWindow");
		ShowWindowIns = mAmg->instantiateAnimation(ShowWindow);

		HideWindow = mAmg->getAnimation("HideWindow");
		HideWindowIns = mAmg->instantiateAnimation(HideWindow);

		SelectionItem = mAmg->getAnimation("SelectionItem");
		SelectionItemIns = mAmg->instantiateAnimation(SelectionItem);

		InverSelectionItem1 = mAmg->getAnimation("InverSelectionItem1");		//move down 30 pixels
		InverSelectionItem1Ins = mAmg->instantiateAnimation(InverSelectionItem1);

		InverSelectionItem2 = mAmg->getAnimation("InverSelectionItem2");
		InverSelectionItem2Ins = mAmg->instantiateAnimation(InverSelectionItem2);

		FontChange1 = mAmg->getAnimation("FontChange1");
		FontChange1Ins = mAmg->instantiateAnimation(FontChange1);

		FontChange2 = mAmg->getAnimation("FontChange2");
		FontChange2Ins = mAmg->instantiateAnimation(FontChange2);

		//GameList->setVisible(false);
		//SettingList->setVisible(false);
		//VolumeList->setVisible(false);
		//ExitList->setVisible(false);
		//AchievementList->setVisible(false);
		GameList->setAlpha(0);
		SettingList->setAlpha(0);
		VolumeList->setAlpha(0);
		ExitList->setAlpha(0);
		AchievementList->setAlpha(0);
	}

	bool onDownClick(const CEGUI::EventArgs &e)
	{	
		endAnimations();
		if(ListType == 0)
		{
			if(SelectedNumber == 3)
			{
				ChangeSelectionInsBottom->setTargetWindow(MainList->getVertScrollbar());
				ChangeSelectionInsBottom->start();
			}
			else if(SelectedNumber < 3 )
			{
					ChangeSelectionIns1->setTargetWindow(MainList->getVertScrollbar());
					ChangeSelectionIns1->start();
					SelectedNumber++;
					switch(SelectedNumber)
					{
					case 0:
						Game->select();
						break;
					case 1:
						Setting->select();
						Game->getChild("GameText")->setFont(fontSmall);
						//Game->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,90)));
						//Game->setHeight(CEGUI::UDim(0,30));
						InverSelectionItem1Ins->setTargetWindow(Game);
						InverSelectionItem1Ins->start();
						Setting->getChild("SettingText")->setFont(fontBig);
						Setting->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Setting->setHeight(CEGUI::UDim(0,60));
						//SelectionItemIns->setTargetWindow(Setting);
						//SelectionItemIns->start();
						Game->getChild("GameText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Setting->getChild("SettingText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						//FontChange2Ins->setTargetWindow(Game->getChild("GameText"));
						//FontChange2Ins->start();
						//FontChange1Ins->setTargetWindow(Setting->getChild("SettingText"));
						//FontChange1Ins->start();
						break;
					case 2:
						Achievement->select();
						Setting->getChild("SettingText")->setFont(fontSmall);
						//Setting->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,150)));
						//Setting->setHeight(CEGUI::UDim(0,30));
						InverSelectionItem1Ins->setTargetWindow(Setting);
						InverSelectionItem1Ins->start();
						Achievement->getChild("AchievementText")->setFont(fontBig);
						Achievement->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						Achievement->setHeight(CEGUI::UDim(0,60));
						Setting->getChild("SettingText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Achievement->getChild("AchievementText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 3:
						Exit->select();
						Achievement->getChild("AchievementText")->setFont(fontSmall);
						//Achievement->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,210)));
						//Achievement->setHeight(CEGUI::UDim(0,30));
						InverSelectionItem1Ins->setTargetWindow(Achievement);
						InverSelectionItem1Ins->start();
						Exit->getChild("ExitText")->setFont(fontBig);
						Exit->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,240)));
						Exit->setHeight(CEGUI::UDim(0,60));
						Achievement->getChild("AchievementText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Exit->getChild("ExitText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					default:
						break;
					}
			}
		}else if(ListType == 1)
		{
			if(SelectedNumber == 0)
			{
				if(GameNumber == 1)
				{
					ChangeSelectionInsBottom->setTargetWindow(GameList->getVertScrollbar());
					ChangeSelectionInsBottom->start();
				}
				else if(GameNumber < 1)
				{
					ChangeSelectionIns1->setTargetWindow(GameList->getVertScrollbar());
					ChangeSelectionIns1->start();
					GameNumber++;
					switch(GameNumber)
					{
					case 0:
						Mode1->select();
						break;
					case 1:
						Mode2->select();
						Mode1->getChild("Mode1Text")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(Mode1);
						InverSelectionItem1Ins->start();
						Mode2->getChild("Mode2Text")->setFont(fontBig);
						Mode2->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Mode2->setHeight(CEGUI::UDim(0,60));
						Mode1->getChild("Mode1Text")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Mode2->getChild("Mode2Text")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					default:
						break;
					}
				}
			}else if(SelectedNumber == 1)
			{
				ChangeSelectionInsBottom->setTargetWindow(SettingList->getVertScrollbar());
				ChangeSelectionInsBottom->start();
			}
		}else if(ListType == 2)
		{
			if(SelectedNumber == 1)
			{
				if(VolumeValue == 5)
				{
					ChangeSelectionInsBottom->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionInsBottom->start();
				}
				else if(VolumeValue < 5)
				{
					ChangeSelectionIns1->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionIns1->start();
					VolumeValue++;
					switch(VolumeValue)
					{
					case 0:
						zero->select();
						break;
					case 1:
						one->select();
						zero->getChild("zeroText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(zero);
						InverSelectionItem1Ins->start();
						one->getChild("oneText")->setFont(fontBig);
						one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						one->setHeight(CEGUI::UDim(0,60));
						zero->getChild("zeroText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						one->getChild("oneText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						two->select();
						one->getChild("oneText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(one);
						InverSelectionItem1Ins->start();
						two->getChild("twoText")->setFont(fontBig);
						two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						two->setHeight(CEGUI::UDim(0,60));
						one->getChild("oneText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						two->getChild("twoText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 3:
						three->select();
						two->getChild("twoText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(two);
						InverSelectionItem1Ins->start();
						three->getChild("threeText")->setFont(fontBig);
						three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,240)));
						three->setHeight(CEGUI::UDim(0,60));
						two->getChild("twoText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						three->getChild("threeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 4:
						four->select();
						three->getChild("threeText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(three);
						InverSelectionItem1Ins->start();
						four->getChild("fourText")->setFont(fontBig);
						four->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,300)));
						four->setHeight(CEGUI::UDim(0,60));
						three->getChild("threeText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						four->getChild("fourText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 5:
						five->select();
						four->getChild("fourText")->setFont(fontSmall);
						InverSelectionItem1Ins->setTargetWindow(four);
						InverSelectionItem1Ins->start();
						five->getChild("fiveText")->setFont(fontBig);
						five->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,360)));
						five->setHeight(CEGUI::UDim(0,60));
						four->getChild("fourText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						five->getChild("fiveText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					}
				}
			}
		}

		return true;
	}

	bool onUpClick(const CEGUI::EventArgs &e)
	{
		endAnimations();
		if(ListType == 0)
		{
			if(SelectedNumber == 0)
			{
				ChangeSelectionInsTop->setTargetWindow(MainList->getVertScrollbar());
				ChangeSelectionInsTop->start();
			}
			else if(SelectedNumber > 0 )
			{
					ChangeSelectionIns2->setTargetWindow(MainList->getVertScrollbar());
					ChangeSelectionIns2->start();
					SelectedNumber--;
					switch(SelectedNumber)
					{
					case 0:
						Game->select();
						Setting->getChild("SettingText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(Setting);
						InverSelectionItem2Ins->start();
						//Setting->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						//Setting->setHeight(CEGUI::UDim(0,30));
						Game->getChild("GameText")->setFont(fontBig);
						Game->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,60)));
						Game->setHeight(CEGUI::UDim(0,60));
						Setting->getChild("SettingText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Game->getChild("GameText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 1:
						Setting->select();
						Achievement->getChild("AchievementText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(Achievement);
						InverSelectionItem2Ins->start();
						//Achievement->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						//Achievement->setHeight(CEGUI::UDim(0,30));
						Setting->getChild("SettingText")->setFont(fontBig);
						Setting->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						Setting->setHeight(CEGUI::UDim(0,60));
						Achievement->getChild("AchievementText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Setting->getChild("SettingText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						Achievement->select();
						Exit->getChild("ExitText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(Exit);
						InverSelectionItem2Ins->start();
						//Exit->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,240)));
						//Exit->setHeight(CEGUI::UDim(0,30));
						Achievement->getChild("AchievementText")->setFont(fontBig);
						Achievement->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						Achievement->setHeight(CEGUI::UDim(0,60));
						Exit->getChild("ExitText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Achievement->getChild("AchievementText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 3:
						Exit->select();
						break;
					}
			}
		}else if(ListType == 1)
		{
			if(SelectedNumber == 0)
			{
				if(GameNumber == 0)
				{
					ChangeSelectionInsTop->setTargetWindow(GameList->getVertScrollbar());
					ChangeSelectionInsTop->start();
				}
				else if(GameNumber > 0)
				{
					ChangeSelectionIns2->setTargetWindow(GameList->getVertScrollbar());
					ChangeSelectionIns2->start();
					GameNumber--;
					switch(GameNumber)
					{
					case 0:
						Mode1->select();
						Mode2->getChild("Mode2Text")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(Mode2);
						InverSelectionItem2Ins->start();
						Mode1->getChild("Mode1Text")->setFont(fontBig);
						Mode1->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,60)));
						Mode1->setHeight(CEGUI::UDim(0,60));
						Mode2->getChild("Mode2Text")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						Mode1->getChild("Mode1Text")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 1:
						Mode2->select();
						break;
					default:
						break;
					}
				}
			}else if(SelectedNumber == 1)
			{
				ChangeSelectionInsTop->setTargetWindow(SettingList->getVertScrollbar());
				ChangeSelectionInsTop->start();
			}
		}else if(ListType == 2)
		{
			if(SelectedNumber == 1)
			{
				if(VolumeValue == 0)
				{
					ChangeSelectionInsTop->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionInsTop->start();
				}
				else if(VolumeValue > 0)
				{
					ChangeSelectionIns2->setTargetWindow(VolumeList->getVertScrollbar());
					ChangeSelectionIns2->start();
					VolumeValue--;
					switch(VolumeValue)
					{
					case 0:
						zero->select();
						one->getChild("oneText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(one);
						InverSelectionItem2Ins->start();
						zero->getChild("zeroText")->setFont(fontBig);
						zero->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,60)));
						zero->setHeight(CEGUI::UDim(0,60));
						one->getChild("oneText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						zero->getChild("zeroText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 1:
						one->select();
						two->getChild("twoText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(two);
						InverSelectionItem2Ins->start();
						one->getChild("oneText")->setFont(fontBig);
						one->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,120)));
						one->setHeight(CEGUI::UDim(0,60));
						two->getChild("twoText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						one->getChild("oneText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 2:
						two->select();
						three->getChild("threeText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(three);
						InverSelectionItem2Ins->start();
						two->getChild("twoText")->setFont(fontBig);
						two->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,180)));
						two->setHeight(CEGUI::UDim(0,60));
						three->getChild("threeText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						two->getChild("twoText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 3:
						three->select();
						four->getChild("fourText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(four);
						InverSelectionItem2Ins->start();
						three->getChild("threeText")->setFont(fontBig);
						three->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,240)));
						three->setHeight(CEGUI::UDim(0,60));
						four->getChild("fourText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						three->getChild("threeText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 4:
						four->select();
						five->getChild("fiveText")->setFont(fontSmall);
						InverSelectionItem2Ins->setTargetWindow(five);
						InverSelectionItem2Ins->start();
						four->getChild("fourText")->setFont(fontBig);
						four->setPosition(CEGUI::UVector2(CEGUI::UDim(0,0),CEGUI::UDim(0,300)));
						four->setHeight(CEGUI::UDim(0,60));
						five->getChild("fiveText")->setProperty("TextColours","tl:FF000000 tr:FF000000 bl:FF000000 br:FF000000");
						four->getChild("fourText")->setProperty("TextColours","tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
						break;
					case 5:
						five->select();
						break;
					}
					PRINT(VolumeValue);
				}
			}
		}
		return true;
	}

	bool onLeftClick(const CEGUI::EventArgs &e)
	{	
		endAnimations();
		switch(ListType)
		{
		case 0:
			break;
		case 1:
			ListType--;
			switch(SelectedNumber)
			{
			case 0:
				//GameList->setVisible(false);
				HideWindowIns->setTargetWindow(GameList);
				HideWindowIns->start();
				break;
			case 1:
				//SettingList->setVisible(false);
				HideWindowIns->setTargetWindow(SettingList);
				HideWindowIns->start();
				break;
			case 2:
				//AchievementList->setVisible(false);
				HideWindowIns->setTargetWindow(AchievementList);
				HideWindowIns->start();
				break;
			case 3:
				//ExitList->setVisible(false);
				HideWindowIns->setTargetWindow(ExitList);
				HideWindowIns->start();
				break;
			}
			//MainList->setVisible(true);
			ShowWindowIns->setTargetWindow(MainList);
			ShowWindowIns->start();
			break;
		case 2:
			ListType--;
			switch(SelectedNumber)
			{
			case 0:
				//GameList->setVisible(true);
				ShowWindowIns->setTargetWindow(GameList);
				ShowWindowIns->start();
				break;
			case 1:
				//VolumeList->setVisible(false);
				//SettingList->setVisible(true);
				HideWindowIns->setTargetWindow(VolumeList);
				HideWindowIns->start();
				ShowWindowIns->setTargetWindow(SettingList);
				ShowWindowIns->start();
				break;
			case 2:
				//AchievementList->setVisible(true);
				ShowWindowIns->setTargetWindow(AchievementList);
				ShowWindowIns->start();
				break;
			case 3:
				//ExitList->setVisible(true);
				ShowWindowIns->setTargetWindow(ExitList);
				ShowWindowIns->start();
				break;
			}
			break;
		default:
			break;
		}
		return true;
	}

	bool onRightClick(const CEGUI::EventArgs &e)
	{	
		endAnimations();
		switch(ListType)
		{
		case 0:
			ListType++;
			//MainList->setVisible(false);
			HideWindowIns->setTargetWindow(MainList);
			HideWindowIns->start();
			switch(SelectedNumber)
			{
			case 0:
				//GameList->setVisible(true);
				ShowWindowIns->setTargetWindow(GameList);
				ShowWindowIns->start();
				break;
			case 1:
				//SettingList->setVisible(true);
				ShowWindowIns->setTargetWindow(SettingList);
				ShowWindowIns->start();
				break;
			case 2:
				//AchievementList->setVisible(true);
				ShowWindowIns->setTargetWindow(AchievementList);
				ShowWindowIns->start();
				break;
			case 3:
				//ExitList->setVisible(true);
				ShowWindowIns->setTargetWindow(ExitList);
				ShowWindowIns->start();
				break;
			}
			break;
		case 1:
			ListType++;
			switch(SelectedNumber)
			{
			case 0:
				HideWindowIns->setTarget(GameList);
				HideWindowIns->start();
				switch(GameNumber)
				{
				case 0:
					//PapaBallSceneManager.getSingleton().setScene("GameScene");
					break;
				case 1:
					//PapaBallSceneManager.getSingleton().setScene("GameScene");
					break;
				}
				//GameList->setVisible(false);  //Game Start
				break;
			case 1:
				HideWindowIns->setTarget(SettingList);
				HideWindowIns->start();
				ShowWindowIns->setTarget(VolumeList);
				ShowWindowIns->start();
				//SettingList->setVisible(false);
				//VolumeList->setVisible(true);
				break;
			case 2:
				HideWindowIns->setTarget(AchievementList);
				HideWindowIns->start();
				//AchievementList->setVisible(false);
				break;
			case 3:
				HideWindowIns->setTarget(ExitList);
				HideWindowIns->start();
				//ExitList->setVisible(false);
				break;
			}
			break;
		case 2:
			break;
		default:
			break;
		}
		return true;
	}

	void endAnimations(void)
	{
		if(ChangeSelectionIns1->isRunning())
		{
			ChangeSelectionIns1->step(0.5);
		}
		if(ChangeSelectionIns2->isRunning())
		{
			ChangeSelectionIns2->step(0.5);
		}
		if(ChangeSelectionInsTop->isRunning())
		{
			ChangeSelectionInsTop->step(0.5);
		}
		if(ChangeSelectionInsBottom->isRunning())
		{
			ChangeSelectionInsBottom->step(0.5);
		}
		if(ShowWindowIns->isRunning())
		{
			ShowWindowIns->step(0.6);
		}
		if(HideWindowIns->isRunning())
		{
			HideWindowIns->step(0.6);
		}
		if(SelectionItemIns->isRunning())
		{
			SelectionItemIns->step(0.5);
		}
		if(InverSelectionItem1Ins->isRunning())
		{
			InverSelectionItem1Ins->step(0.5);
		}
		if(InverSelectionItem2Ins->isRunning())
		{
			InverSelectionItem2Ins->step(0.5);
		}
	}
	virtual void destroyScene(void)
	{
		MenuManager::getSingleton().Deactive(false);
		destroyAnimations();
		CEGUI::WindowManager::getSingleton().destroyAllWindows();
	}

	virtual void destroyAnimations(void)
	{
		ChangeSelectionIns1->stop();
		ChangeSelectionIns2->stop();
		ChangeSelectionInsTop->stop();
		ChangeSelectionInsBottom->stop();
		ShowWindowIns->stop();
		HideWindowIns->stop();
		SelectionItemIns->stop();
		InverSelectionItem1Ins->stop();
		InverSelectionItem2Ins->stop();
		FontChange1Ins->stop();
		FontChange2Ins->stop();

		mAmg->destroyAnimationInstance(ChangeSelectionIns1);
		mAmg->destroyAnimationInstance(ChangeSelectionIns2);
		mAmg->destroyAnimationInstance(ChangeSelectionInsTop);
		mAmg->destroyAnimationInstance(ChangeSelectionInsBottom);
		mAmg->destroyAnimationInstance(ShowWindowIns);
		mAmg->destroyAnimationInstance(HideWindowIns);
		mAmg->destroyAnimationInstance(SelectionItemIns);
		mAmg->destroyAnimationInstance(InverSelectionItem1Ins);
		mAmg->destroyAnimationInstance(InverSelectionItem2Ins);
		mAmg->destroyAnimationInstance(FontChange1Ins);
		mAmg->destroyAnimationInstance(FontChange2Ins);

		mAmg->destroyAnimation(ChangeSelection1);
		mAmg->destroyAnimation(ChangeSelection2);
		mAmg->destroyAnimation(ChangeSelectionTop);
		mAmg->destroyAnimation(ChangeSelectionBottom);
		mAmg->destroyAnimation(ShowWindow);
		mAmg->destroyAnimation(HideWindow);
		mAmg->destroyAnimation(SelectionItem);
		mAmg->destroyAnimation(InverSelectionItem1);
		mAmg->destroyAnimation(InverSelectionItem2);
		mAmg->destroyAnimation(FontChange1);
		mAmg->destroyAnimation(FontChange2);
	}


private:
	CEGUI::WindowManager *mWmg;
	CEGUI::ItemListbox *MainList,*GameList,*SettingList,*AchievementList,*ExitList,*VolumeList;
	CEGUI::ItemEntry *Game,*Setting,*Achievement,*Exit,*Mode1,*Mode2,*Volume,*zero,*one,*two,*three,*four,*five;
	int SelectedNumber,ListType; //ListType 0,1,2
	int GameNumber,VolumeValue;
	CEGUI::AnimationManager *mAmg;
	CEGUI::Animation *ChangeSelection1,*ChangeSelection2,*ChangeSelectionTop,*ChangeSelectionBottom,
		*ShowWindow,*HideWindow,*SelectionItem,*InverSelectionItem1,*InverSelectionItem2,
		*FontChange1,*FontChange2;
	CEGUI::AnimationInstance *ChangeSelectionIns1,*ChangeSelectionIns2,*ChangeSelectionInsTop,*ChangeSelectionInsBottom,
		*ShowWindowIns,*HideWindowIns,*SelectionItemIns,*InverSelectionItem1Ins,*InverSelectionItem2Ins,
		*FontChange1Ins,*FontChange2Ins;
	CEGUI::Font *fontSmall,*fontBig;

};
